Why do I get this Debug Assertion Failed? Expression: list iterator not dereferenceable [migrated]
Posted
by
Karel
on Programmers
See other posts from Programmers
or by Karel
Published on 2012-12-15T14:16:42Z
Indexed on
2012/12/15
17:17 UTC
Read the original article
Hit count: 310
I'm trying this example in the (translated to dutch) book of Bjarne Stroustrup (C++):
#include <vector>
#include <list>
#include "complex.h"
complex ac[200];
std::vector<complex> vc;
std::list<complex> l;
template<class In, class Out> void Copy(In from, In too_far, Out to) {
while(from != too_far) {
*to = *from;
++to;
++from;
}
}
void g(std::vector<complex>& vc , std::list<complex>& lc) {
Copy(&ac[0], &ac[200], lc.begin()); // generates debug error
Copy(lc.begin(), lc.end(), vc.begin()); // also generates debug error
}
void f() {
ac[0] = complex(10,20);
g(vc, l);
}
int main () {
f();
}
** Compiling and Linking goes successful (0 errors/warnings)**
But at runtime I get this error:
Debug Assertion Failed!
Program: path to exe
file: \program files\ms vs studio 10.0\vc\include\list
Line: 207
Expression: list iterator not dereferenceable
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug the application)
© Programmers or respective owner